package be.idamf.cortizone.fileprocessor
{
	import flash.filesystem.File;

	[DefaultProperty("criteria")]
	
	public class FileFilterProcessor implements IFileProcessor
	{
		[Bindable]
		public var criteria:FileFilterCriteria;
		
		public function FileFilterProcessor()
		{
		}
		
		public function reset():void
		{
			if (criteria == null)
				criteria = new FileFilterCriteria();
		}
		
		public function cancel():void
		{
		}
		
		public function process(file:File):Boolean
		{
			if (criteria.extension && !file.extension)
				return false;
			
			if (criteria.extension && file.extension && criteria.extension.toLowerCase() != file.extension.toLowerCase())
				return false;
			
			if (criteria.contains && file.name.indexOf(criteria.contains) == -1)
				return false;
			
			if (criteria.beforeDate && criteria.beforeDate.getTime() < file.modificationDate.getTime())
				return false;
			
			if (criteria.afterDate && criteria.afterDate.getTime() > file.modificationDate.getTime())
				return false;

			return true;
		}
	}
}